﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using FastDFS.Client;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {

        public ActionResult Index()
        {
            ViewBag.Message = "欢迎使用 ASP.NET MVC!";

            return View();
        }
        [HttpPost]
        public ActionResult Index(FormCollection form)
        {
            //Initial
            List<IPEndPoint> trackerIPs = new List<IPEndPoint>();
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("192.168.2.50"), 22122);
            trackerIPs.Add(endPoint);
            ConnectionManager.Initialize(trackerIPs);
            StorageNode node = FastDFSClient.GetStorageNode("fdfsgroup1");
            //上传文件
            byte[] content = null;

            using (BinaryReader reader = new BinaryReader(Request.Files[0].InputStream))
            {
                content = reader.ReadBytes((int)Request.Files[0].InputStream.Length);
            }

            string fileName = FastDFSClient.UploadFile(node, content, "xls");
            ViewBag.Msg = "http://192.168.2.50/fdfsgroup1/" + fileName;

            return View();
        }
        public ActionResult About()
        {
            return View();
        }

        public ActionResult RedisMSMQ()
        {
            Redis.Utils.RedisClient redis = new Redis.Utils.RedisClient();
            ViewBag.Msg = redis.LeftPop("ErrorCallback");
            return View();
        }
    }
}
